package chapter2.No2_2_synchronized同步语句块.o内置类与同步_实验2;

/**
 * Created by Administrator on 2016/11/14.
 */
public class PublicClass {

    static class PrivateClass {
        public void methodA(StaticClass staticClass) {
            System.out.println(Thread.currentThread().getName() + " A方法开始运行");

            synchronized (staticClass) {
                for (int i = 0; i < 10; i++) {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName() + " 值：" + i);
                }
            }
            System.out.println(Thread.currentThread().getName() + " A方法结束运行");
        }

        public synchronized void methodB() {
            System.out.println(Thread.currentThread().getName() + " B方法开始运行");
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " 值：" + i);
            }
            System.out.println(Thread.currentThread().getName() + " B方法结束运行");
        }

    }

    static class StaticClass {
        public synchronized void methodC() {
            System.out.println(Thread.currentThread().getName() + " C方法开始运行");
            for (int i = 0; i < 10; i++) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " 值：" + i);
            }
            System.out.println(Thread.currentThread().getName() + " C方法结束运行");
        }
    }

}
